#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct book
{
	char bookname[30];
	int price;
};

int cmp1(const void* pa, const void* pb)
{
	return strcmp(((struct book*)pa)->bookname,((struct book*)pb)->bookname);
}

int cmp2(const void* pa, const void* pb)
{
	return ((struct book*)pa)->price - ((struct book*)pb)->price;
}

void Print(struct book s[], size_t sz)
{
	for (int i = 0;i < sz; i++)
	{
		printf("%s %d\n", s[i].bookname, s[i].price);
	}
	printf("\n");
}

void sort1()
{
	struct book s[] = { { "Stranger Things",30 }, { "Harry Potter",24},{ "Teddy Bear",25 } };
	size_t sz = sizeof(s) / sizeof(s[0]);
	qsort(s, sz, sizeof(struct book), cmp1);
	Print(s, sz);
}

void sort2()
{
	struct book s[] = { { "Stranger Things",30 }, { "Harry potter",24 },{ "Teddy bear",25 } };
	size_t sz = sizeof(s) / sizeof(s[0]);
	qsort(s, sz, sizeof(struct book), cmp2);
	Print(s, sz);
}

int main()
{
	sort1();
	sort2();
	return 0;
}